/**
 * Copyright (c) 2017 hadlinks, All Rights Reserved.
 */
package com.bugull.farm.core.control.task;

import com.bugull.farm.core.control.task.callable.UpperControlCallable;
import com.bugull.farm.core.server.FarmServer;
import com.bugull.farm.core.store.CommandTask;
import io.netty.channel.ChannelHandlerContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.FutureTask;

/**
 * Project Name: bugu-farm-household
 * Package Name: com.bugull.farm.device.shortconn.server.control.task 
 * ClassName: UpperControlFutureTask 
 * Function: TODO ADD FUNCTION.  
 * date: 2017/7/20 16:30
 * @author songwei (songw@hadlinks.com)
 * @since JDK 1.8 
 */
public class UpperControlFutureTask extends FutureTask<Boolean> {

    private CommandTask commandTask;
    private Long createTime;//任务创建时间
    private Boolean repeat;//任务失败重试标识
    private Logger logger = LogManager.getLogger(UpperControlFutureTask.class);

    public UpperControlFutureTask(UpperControlCallable callable) {
        super(callable);
        this.commandTask = callable.getCommandTask();
        this.createTime = callable.getCreateTime();
    }

    @Override
    protected void done() {
//        try {
//            if (!get()) { //callable任务执行失败时
//                //检查设备是否还在连接状态
//                DeviceCache cache = DeviceCache.getInstance();
//                String channelId = cache.getChannelId(commandTask.getTerminalSN());
//                channelId = channelId == null ? "" : channelId;
//                ChannelHandlerContext ctx = cache.getContext(channelId);
//                if (ctx != null && !repeat) { //检查连接状态，离线不执行任务
//                    //第一次失败时直接放入队尾进行重试
//                    FarmServer.getThreadPool().submit(new UpperControlFutureTask(new UpperControlCallable(commandTask)));
//                    this.repeat = Boolean.TRUE;
//                }
//            }
//        } catch (Exception e) {
//            logger.error("存量模块{}设置命令任务回调处理失败!!!", commandTask.getTerminalSN(), e);
//        }
    }
}
